<?php
	include 'class/Markers.php';

class Reserva{
	
	private $id;
	private $fkMarker;
	private $fkCliente;
	private $date;
	private $marker;
	
	public function construtor($id, $fkMarker, $fkCliente, $date){
		$this->fkCliente=$fkCliente;
		$this->fkMarker=$fkMarker;
		$this->date=$date;
		$this->id=$id;
	}
	
	public function _contrutor($fkMarker, $fkCliente){
		$this->fkCliente=$fkCliente;
		$this->fkMarker=$fkMarker;
	}
	
	public function save(){
		$sql= "INSERT INTO reserve (reserve_fk_marker,reserve_fk_client) VALUES ('".$this->fkMarker."','".$this->fkCliente."');";
		return mysql_query($sql);
	}
	
	public function update(){}
	
	public function search($clienteId){
		$arrayList = new ArrayList();
		
		$sql = "SELECT * FROM reserve, client, markers WHERE client.client_id='$clienteId' AND reserve.reserve_fk_client=client.client_id AND reserve.reserve_fk_marker=markers.id;";
		$reservas = mysql_query($sql) or die("Houve um erro ao consultar reservas !<br><br>".mysql_error());
		
		while($reserva = mysql_fetch_array($reservas)){
		
			$id=$reserva['reserve_id'];
			$date=$reserva['reserve_date'];
			$fkMarker=$reserva['reserve_fk_marker'];
			$fkCliente=$reserva['reserve_fk_client'];
			$markerName = $reserva['name'];
			
			$marker = new Markers();
			$marker->setName($markerName);
			
			$objReserva = new Reserva();
			$objReserva->construtor($id, $fkMarker, $fkCliente, $date);
			$objReserva->setMarker($marker);
					
			$arrayList->add($objReserva);
		}
		
		//retorna um ArrayList com os objetos
		return $arrayList;
	}
	
	public function setId($id){
		$this->id = $id;
	}
	
	public function setFkMarker($fkMarker){
		$this->fkMarker=$fkMarker;
	}
	
	public function setFkCliente($fkCliente){
		$this->fkCliente=$fkCliente;
	}
	
	public function setDate($date){
		$this->date=$date;
	}
	
	public function setMarker($marker){
		$this->marker = $marker;
	}
	
	public function getId(){
		return $this->id;
	}
	
	public function getFkMarker(){
		return $this->fkMarker;
	}
	
	public function getFkCliente(){
		return $this->fkCliente;
	}
	
	public function getDate(){
		return $this->date;
	}
	
	public function getMarker(){
		return $this->marker;
	}
}
?>